<template>
  <div>
    <!-- <div>用户名：<input type="text" name="" id="" v-model="user.phone" /></div>
    <div>密码：<input type="password" v-model="user.password" /></div>
    <div>{{ user }}</div>
    <div>没有账号？<router-link to="/register">去注册</router-link></div>
    <v-button @click="login">登录</v-button> -->
    <van-form @submit="login">
        <van-field
          v-model="user.phone"
          name="用户名"
          label="用户名"
          placeholder="用户名"
          :rules="[{ required: true, message: '用户名不能为空' }]"
        />
        <van-field
          v-model="user.password"
          type="password"
          name="密码"
          label="密码"
          placeholder="密码"
          :rules="[{ required: true, message: '密码不能为空' }]"
        />
      <div style="margin: 16px">
        <van-button round block type="warning" native-type="submit">
          提交
        </van-button>
      </div>
    </van-form>
  </div>
</template>
<script>
import { reqLogin } from "../../http/http";
export default {
  data() {
    return {
      user: {
        password: "",
        phone: "",
      },
    };
  },
  methods: {
    async login() {
      let { data: result } = await reqLogin(this.user);
      if (result.code == 200) {
        alert(result.msg);
        window.localStorage.setItem("isLogin", JSON.stringify(result.list));
        this.$router.push("/index");
      } else {
        alert(result.msg);
      }
    },
  },
};
</script>

<style scoped>
</style>